<template>
	<view>
		<view class="" style="padding-bottom: 120rpx;">
			<view class="mainpadding ffffff xiahuaxian">
				<!-- 有地址 -->
				<view class="flexbetween" v-if="addressData">
					<view class="flexleft">
						<view class=" margin_right3">
							<u-icon name="map-fill" color="#2979ff" size="28"></u-icon>
						</view>
						<view class="">
							<view class="xiaohui sanshier nofonweight">{{addressData.name}}，{{addressData.mobile}}</view>
							<view class="xiaohui sanshier nofonweight margin_top1">{{addressData.cityinfo}}{{addressData.address_detail}}</view>
						</view>
					</view>
					<view class="xgdzbtn" @click="tzdzlb">修改地址</view>
				</view>
				<!-- 无地址 -->
				<view class="flexbetween" v-else>
					<view class="flexleft">
						<view class=" margin_right3">
							<u-icon name="map" color="#2979ff" size="28"></u-icon>
						</view>
						<view class="bigtext xiaohei nofonweight">请选择地址</view>
					</view>
					<view class="xgdzbtn" @click="tzdzlb">选择地址</view>
				</view>
			</view>
			<!-- 订单详情 -->
			<view class="mainpadding ffffff xiahuaxian" v-for="item in orderData.lists" :key="item.products.id">
				<view class="flexbetween">
					<view class="shangp">
						<image :src="item.products.image_text" mode=""></image>
					</view>
					<view class="" style="width: 70%;">
						<view class="sanshier xiaohei yhxk">{{item.products.name}}</view>
						<view class="flexbetween margin_top">
							<view class="xiaohui nofonweight titletext">制作材料: {{item.products.zzcl}}</view>
							<view class="xiaohei nofonweight titletext">规格: {{item.products.sku}}</view>
						</view>
						<view class="flexbetween margin_top2">
							<view class="xiaohong bigtext fonweight">￥{{item.products.price}}</view>
						</view>
					</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="xiaohei nofonweight titletext">库号: {{item.products.kh}}</view>
					<view class="xiaohei nofonweight titletext">作者: {{item.products.auther}}</view>
				</view>
			</view>
			<!-- <view class="mainpadding ffffff xiahuaxian">
				<view class="flexbetween">
					<view class="xiaohei sanshier">下单时间</view>
					<view class="xiaohui sanshier">2022-10.20</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="xiaohei sanshier">订单编号</view>
					<view class="xiaohui sanshier">410355662</view>
				</view>
			</view> -->			
		</view>
		<view class="gudingdb ffffff mainpadding">
			<view class="bigbtn" @click="submit()">确认兑换</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				addressData:"",
				address_id:"",
				listid:"",
				orderData:{}
			}
		},
		onLoad(options) {
			this.listid = options.id
		},
		onShow() {
			uni.$off("checkaddress")
			uni.$on("checkaddress",data=>{
				this.address_id = data
			})
			this.init()
		},
		methods: {
			init(){
				httpRequest.request("/api/Scoregoods/getOrderGoodsList/", 'POST', {
					address_id:this.address_id,
					type:"detail",
					data:[{
						goods_id:this.listid,
						number:1
					}]
				}, false, false, true).then(res => {
					this.addressData = res.data.addressData
					if(res.data.addressData){
						this.address_id = res.data.addressData.id
					}
					this.orderData = res.data.orderData
					this.pageShow = true
				})
			},
			submit(){
				if(this.address_id==""){
					httpRequest.toast("请选择收货地址")
					return false
				}
				httpRequest.request("/api/scoregoods/addOrder", 'POST', {
					address_id:this.address_id,
					type:"detail",
					data:[{
						goods_id:this.listid,
						number:1
					}]
				}, false, false, true).then(res => {
					if(res.code==1){
						this.pay(res.data.id)
					}else{
						httpRequest.toast(res.msg)
					}
				})
			},
			pay(id){
				httpRequest.request("/api/scoregoods/paymentOrder", 'GET', {
					id
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						setTimeout(()=>{
							uni.redirectTo({
								url:"/pages/dingdan/duihuanqd"
							})
						},1000)
					}
				})
			},
			// 跳转地址列表
			tzdzlb(){
				uni.navigateTo({
					url:'/pages/mypage/shouhuodizhi?type=1'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.shangp {
		width: 180rpx;
		height: 180rpx;
		border-radius: 10rpx;
	
		image {
			width: 100%;
			height: 100%;
			border-radius: 10rpx;
		}
	}
	.xgdzbtn {
		width: 161rpx;
		height: 61rpx;
		background: #FFFFFF;
		border: 1px solid #DDDDDD;
		border-radius: 30rpx;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>
